package com.emser.unc.client.presenter;

import com.emser.unc.client.CloudMobile;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.HasText;
import com.google.gwt.user.client.ui.HasWidgets;
import com.google.gwt.user.client.ui.Widget;

public class HeaderPresenter implements Presenter{
	private final Display display; 
	
	public interface Display {	
		HasClickHandlers getLogoutButton();
	    Widget asWidget();
	    HasText getUserNameLabel();   
	  }
	
	public HeaderPresenter(  Display display) {
		this.display = display;
		bind();
	}
		
	private void bind() {
		this.display.getLogoutButton().addClickHandler(new ClickHandler() {   
		      public void onClick(ClickEvent event) {
		    	  doLogout();
		      }
		 });
	}
	
	private void doLogout() {
		Window.Location.assign(CloudMobile.constants.urlServletLogout());
	  }
	
	public void setUserName(String userName){
		this.display.getUserNameLabel().setText(userName);
	}
	
	@Override
	public void go(HasWidgets container) {
		container.clear();
	    container.add(display.asWidget());
	}

}
